package com.atwu.wl2022.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动添加时间工具类
 * @author wulejay
 */
@Component
@Slf4j
public class MyHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		log.info("更新创建时间：{}",new Date());
		this.setFieldValByName("createDate",new Date(),metaObject);
		this.setFieldValByName("modifiedDate",new Date(),metaObject);
		this.setFieldValByName("createTime",new Date(),metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		log.info("更新插入时间：{}",new Date());
		this.setFieldValByName("modifiedDate",new Date(),metaObject);
	}
}
